﻿using System;
using System.Collections.Generic;

namespace Conv
{
    public class ConvolutinalLayer:ITeacheble
    {
        public List<Layer> MapList { get; protected set; }
        public int FeatureMapCount { get; protected set; }
        /*public ConvolutinalLayer(List<Layer> previousLayerFeatureMapList, int featureMapCount, int maskSize)
        {
            FeatureMapCount = featureMapCount;
            MapList = new List<Layer>(featureMapCount * previousLayerFeatureMapList.Count);
            for (int i = 0; i < featureMapCount; i++)
            {
                //MapList.Add(new ConvolutionalFeatureMap(previousLayerFeatureMapList, maskSize, maskSize,
                //    x => Math.Tanh(x), x => 1 - (1.7159 * Math.Tanh(x)) * (1.7159 * Math.Tanh(x)))); //WARNING experimetal coeffs
                MapList.Add(new ConvolutionalFeatureMap(previousLayerFeatureMapList, maskSize, maskSize,
                    x => Math.Tanh(x), x => 1 - Math.Tanh(x) * Math.Tanh(x))); 
            }
        }*/

        //This constructor for connection to one FM
        public ConvolutinalLayer(List<Layer> previousLayerFeatureMapList, int featureMapCount, int maskSize)
        {
            FeatureMapCount = featureMapCount;
            MapList = new List<Layer>(featureMapCount * previousLayerFeatureMapList.Count);
            for (int i = 0; i < featureMapCount; i++)
            {
                //MapList.Add(new ConvolutionalFeatureMap(previousLayerFeatureMapList, maskSize, maskSize,
                //    x => Math.Tanh(x), x => 1 - (1.7159 * Math.Tanh(x)) * (1.7159 * Math.Tanh(x)))); //WARNING experimetal coeffs
                //MapList.Add(new ConvolutionalFeatureMap(previousLayerFeatureMapList[i%previousLayerFeatureMapList.Count], maskSize, maskSize,
                //    x => Math.Tanh(x), x => 1 - Math.Tanh(x) * Math.Tanh(x)));

                //Act funct from DemoMNist code
                MapList.Add(new ConvolutionalFeatureMap(previousLayerFeatureMapList, maskSize, maskSize,
                    x => 1.7159 * Math.Tanh(x * 2 / 3), x => -1.44 * Math.Tanh(2 * x / 3) * Math.Tanh(2 * x / 3) + 1.44)); //WARNING experimetal coeffs
            }
        }
        public void BackPropogate()
        {
            foreach (Layer FM in MapList)
            {
                FM.BackPropogate();
            }
        }

        public void Process()
        {
            foreach (var fm in MapList)
            {
                fm.Process();
            }
        }
        public void UpdateWeight()
        {
            foreach (var FM in MapList)
            {
                FM.UpdateWeight();//May be here something other
            }
        }
    }
}